﻿@model PcaCore.BOL.Pca.oEmpresa

@{
    var X = Html.X();
}

@(
 X.GridPanel()
        .Title("Lista de empresas")
        .Flex(1)
        .Store(
            X.StoreForModel()
                .ID("storeEmpresas")
                .Proxy(X.AjaxProxy()
                    .Url(Url.Action("GetListEmpresas"))
                    .Reader(X.JsonReader().RootProperty("data"))
                )
                .RemoteSort(false)
                .PageSize(20)
        )
        .DirectEvents(de =>
        {
            de.ItemDblClick.Url = Url.Action("RunCommandGrid", "Empresas");
            de.ItemDblClick.ExtraParams.Add(new Parameter { Name = "commandName", Value = "cmdEditar", Mode = ParameterMode.Value });
            de.ItemDblClick.ExtraParams.Add(new Parameter { Name = "empresaId", Value = "record.data.empresa_id", Mode = ParameterMode.Raw });
            de.ItemDblClick.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
            de.ItemDblClick.Complete = "Ext.getBody().unmask();";
            de.ItemDblClick.Failure = "PcaGlobal.showError(result.msg);";
        })
        .ColumnModel(
                X.Column().DataIndex(Model, m => m.empresa_id).Text("ID").Width(70),
                X.Column().DataIndex(Model, m => m.codigo).Text("Codigo(Ruc)").Flex(1),
                X.Column().DataIndex(Model, m => m.nombre).Text("Nombre").Flex(1),
                X.Column().DataIndex(Model, m => m.direccion).Text("Direccion").Flex(1),
                X.DateColumn().DataIndex(Model, m => m.fecha_registro).Text("Registrado").Format("dd-MM-yyyy").Align(Alignment.Center),
                X.CheckColumn().DataIndex(Model, m => m.activo).Text("Activo?").Width(70),
                X.CommandColumn().Hideable(false).Text("Operaciones").Align(Alignment.Center)
                    .Commands(
                        X.GridCommand().CommandName("cmdEditar").ToolTip(t => t.Text = "Editar empresa").Icon(Icon.ApplicationEdit),
                        X.GridCommand().CommandName("cmdEliminar").ToolTip(t => t.Text = "Eliminar empresa").Icon(Icon.ApplicationDelete)
                    )
                    .DirectEvents(de =>
                    {
                        de.Command.Url = Url.Action("RunCommandGrid", "Empresas");
                        de.Command.ExtraParams.Add(new Parameter { Name = "commandName", Value = "command", Mode = ParameterMode.Raw });
                        de.Command.ExtraParams.Add(new Parameter { Name = "empresaId", Value = "record.data.empresa_id", Mode = ParameterMode.Raw });
                        de.Command.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                        de.Command.Complete = "Ext.getBody().unmask();";
                        de.Command.Failure = "PcaGlobal.showError(result.msg);";
                    })
       )
       .TopBar(
            X.Toolbar()
                .Items(
                    X.Button()
                        .Text("Nueva empresa")
                        .Icon(Icon.Add)
                        .DirectEvents(de =>
                        {
                            de.Click.Url = Url.Action("FrmRegistrar", "Empresas");
                            de.Click.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                            de.Click.Complete = "Ext.getBody().unmask();";
                        })
                )
       )
       .BottomBar(
            X.PagingToolbar()
                .DisplayInfo(true)
                .DisplayMsg("Mostrando empresas {0}-{1} de {2}")
                .EmptyMsg("No existen empresas")
       )
)
